from typing import Optional
from paddleocr import PaddleOCR

ocr = PaddleOCR(lang="ch", show_log=False, mode="PP-OCRv4")


def ocr_price(img_path: str) -> Optional[float]:
    result = ocr.ocr(img_path, cls=True)
    for one in result[0]:
        ocr_tuple = one[1]
        ocr_string, confidence = ocr_tuple
        try:
            ocr_float = float(ocr_string)
            return ocr_float
        except Exception as e:
            pass
    return None


failed_img = "./data/failed/454_None.jpg"

result = ocr.ocr(failed_img, cls=True)
for one in result[0]:
    print(one)
